/*LICENSE_BEGIN
 * ******************************************************************
 * All original parts of SoccerScope2003 have copyright (2003) by
 * Team YowAI, represented by Mr. Shuhei Shiota
 * The Department of Creative Informatics
 * The Graduate School of Information Science and Technology
 * The University of Tokyo
 * 
 * Additional classes (except libraries in /lib) were developed by 
 * the Dainamite Robocup-Team of the DAI-Labor, TU-Berlin 
 * (www.dai-labor.de)
 * 
 * Extended/new classes/packages are:
 *   soccerscope.analyzer.LogfileAnalyzer
 *   soccerscope.daistatistic.*
 *   soccerscope.daistatistic.charts.*
 *   soccerscope.daistatistic.tools.*
 *   soccerscope.db.*
 *   soccerscope.dialog.*
 *   soccerscope.model.PlayerWorldModel
 *   soccerscope.model.SimplePlayer
 *   soccerscope.net.AgentConnector
 *   soccerscope.training.*
 *   soccerscope.training.conditions.*
 * ******************************************************************
LICENSE_END*/
package soccerscope.daistatistic;

import robocup.component.RobocupAgent;
import robocup.component.StateTactic;

/**
 * 
 * this class performs all gui player actions which need an thread (actions
 * which needs more than one cycle)
 */

class Actions {

	// selectors for the action
	public static final int Mode_searchBall = 2;

	public static final int Mode_goToBall = 3;

	// pre-define needed variables
	public static double xPos = 0;

	public static double yPos = 0;

	public static int power = 100;

	// flags
	public static boolean searchBallGoesOn = false;

	public static boolean goToBall = false; // continue go to the ball

	public static boolean runToPos = false; // continue run to position

	/**
	 * main methode, creates selected threads and start them
	 * 
	 * @param player
	 *            the player
	 * @param tactic
	 *            the player's tactic
	 * @param selected
	 *            Action/Mode
	 */
	public static void start(StateTactic tactic, RobocupAgent player, int mode) {

		// search Ball selected
		if (mode == Mode_searchBall) {
			if (!searchBallGoesOn) {
				ActionSearchBall searchBall = new ActionSearchBall(); // create
				// a new
				// ActionSearchBall
				// class
				searchBall.tactic = tactic; // commit needed values to the class
				searchBall.player = player;
				searchBallGoesOn = true;
				Thread th = new Thread(searchBall); // create a new thread
				th.start(); // start the thread
			} else {
				searchBallGoesOn = false;
			}

		}

		// go to Ball selected
		if (mode == Mode_goToBall) {
			if (!goToBall) {
				ActionGoToBall searchBall = new ActionGoToBall(); // create a
				// new
				// ActionGoToBall
				// class
				searchBall.tactic = tactic; // commit needed values to the class
				Thread th = new Thread(searchBall); // create a new thread
				th.start(); // start the thread
				goToBall = true; // go to ball is active
			} else {
				goToBall = false; // turn thread off
			}
		}
	}
}

class ActionSearchBall implements Runnable {

	public StateTactic tactic; // committed values

	public RobocupAgent player;

	public void run() {
		while (Actions.searchBallGoesOn) { // while player don't sees the ball
			// do..
			// tactic.searchBall(); //call TacticBean.searchBall
			try {
				Thread.sleep(50); // wait a while for the next move
			} catch (Exception e) {
			}
		}
	}
}

class ActionGoToBall implements Runnable {

	public StateTactic tactic; // committed value

	public void run() {
		// while ( Actions.goToBall){ //while goToBall = true go to the ball
		// tactic.goToBall(); //call TacticBean.goToBall
		try {
			Thread.sleep(50); // wait a while for the next move
		} catch (Exception e) {
		}
		// }
	}
}